1 module unde.games.dizzy.omega.animations.things_sweep_away_zaks;
2 
3 import derelict.opengl3.gl;
4 
5 import std.algorithm;
6 import std.conv;
7 import std.math;
8 import std.stdio;
9 import unde.games.dizzy.omega.bug;
10 import unde.games.dizzy.omega.grasshopper;
11 import unde.games.dizzy.omega.bird;
12 import unde.games.dizzy.omega.fish;
13 import unde.games.dizzy.omega.squid;
14 import unde.games.dizzy.omega.dizzy;
15 import unde.games.dizzy.omega.main;
16 import unde.games.object;
17 import unde.games.renderer;
18 import unde.games.collision_detector;
19 import unde.games.object;
20 import unde.global_state;
21 
22 class ThingsSweepAwayZaks:StaticGameObject
23 {
24     int frame = -1;
25     bool hidden;
26 
27     StaticGameObject[] things;
28     
29     this(MainGameObject root)
30     {
31         hidden = true;
32         
33         x = 463.0;
34         y = -158.9;
35         z = 0.0;
36 
37         things = [ new Bug(root, [x, y, z], "underground-solid", true),
38                    new Bug(root, [x-4.0, y, z-1.0], "underground-solid", true),
39                    new Bug(root, [x-8.0, y, z+1.0], "underground-solid", true),
40                    new Bug(root, [x-12.0, y, z], "underground-solid", true),
41                    new Bug(root, [x-2.0, y, z-1.0], "underground-solid", true),
42                    new Bug(root, [x-6.0, y, z+1.0], "underground-solid", true),
43                    new Bug(root, [x-10.0, y, z], "underground-solid", true),
44                    new Grasshopper(root, [x, y, z-1.0], "underground-solid", null, null),
45                    new Grasshopper(root, [x-4.0, y, z+1.0], "underground-solid", null, null),
46                    new Grasshopper(root, [x-8.0, y, z], "underground-solid", null, null),
47                    new Grasshopper(root, [x-12.0, y, z-1.0], "underground-solid", null, null),
48                    new Grasshopper(root, [x-2.0, y, z+1.0], "underground-solid", null, null),
49                    new Grasshopper(root, [x-6.0, y, z], "underground-solid", null, null),
50                    new Grasshopper(root, [x-10.0, y, z-1.0], "underground-solid", null, null),
51                    new Bird(root, [x-5.0, y+5.0, z-5.0], x+35.0, null, 300),
52                    new Bird(root, [x-10.0, y+7.0, z-5.0], x+35.0, null, 300),
53                    new Bird(root, [x-15.0, y+3.0, z-5.0], x+35.0, null, 300),
54                    new Fish(root, [481.1, -162.0, 0.0], 481.1, 500.0, 1.0, 0.5, -158.3, 400),
55                    new Fish(root, [481.1, -164.0, 0.0], 481.1, 500.0, 0.6, 0.5, -158.3, 500),
56                    new Fish(root, [481.1, -166.0, 0.0], 481.1, 500.0, 0.8, 0.5, -158.3, 600),
57                    new Squid(root, [481.1, -155.72+4.0, 0.0], -158.3+4.0, -164.0, 0.03, 450),
58                    new Squid(root, [481.1, -155.72+4.0, 0.0], -158.3+4.0, -164.0, 0.03, 550),
59                    new Squid(root, [481.1, -155.72+4.0, 0.0], -158.3+4.0, -164.0, 0.03, 650),
60                    ];
61         
62         super(root);
63     }
64 
65     void unhide()
66     {
67         hidden = false;
68     }
69 
70     void hide()
71     {
72         hidden = true;
73     }
74 
75     override void draw(GlobalState gs)
76     {
77         if ( abs(root.scrx-x) > 32.0 &&
78              abs(root.scry-y) > 18.0 )
79             return;
80 
81         if (!hidden)
82         {
83             foreach(thing; things)
84             {
85                 thing.draw(gs);
86             }
87         }
88     }
89     
90     override bool tick(GlobalState gs)
91     {
92         if ( hidden || abs(root.scrx-x) > 32.0 &&
93                 abs(root.scry-y) > 18.0 )
94             return true;
95 
96         frame++;
97         foreach(thing; things)
98         {
99             thing.tick(gs);
100         }
101 
102         return true;
103     }
104 
105     override void load(string[string] s)
106     {
107         string p = "sweep";
108 
109         if (p in s)
110             hidden = (s[p] != "not-hidden");
111         else
112             hidden = true;
113             
114         if (p~"-frame" in s)
115             frame = s[p~"-frame"].to!(int);
116         else
117             frame = 0;
118 
119         foreach(thing; things)
120         {
121             thing.load(s);
122         }
123     }
124 
125     override void save(ref string[string] s)
126     {
127         string p = "sweep";
128         if (!hidden)
129             s[p] = "not-hidden";
130 
131         s[p~"-frame"] = frame.to!(string);
132             
133         foreach(thing; things)
134         {
135             thing.save(s);
136         }
137     }
138 }
139